package cn.nkpro.elcube.docengine.cloud;

import cn.nkpro.elcube.cloud.NkAbstractCloudService;
import cn.nkpro.elcube.data.elasticearch.ESPageList;
import cn.nkpro.elcube.docengine.NkDocSearchService;
import cn.nkpro.elcube.docengine.model.SearchParams;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;

/**
 * 单据搜索服务代理
 */
public class NkCloudDocSearchService extends NkAbstractCloudService<NkDocSearchService> implements NkDocSearchService {


    @Override
    public void init() throws IOException {
        local().init();
    }

    @Override
    public void createDefaultRecord() {
        local().createDefaultRecord();
    }

    @Override
    public void dropAndInit() throws IOException {
        local().dropAndInit();
    }

    @Override
    public boolean exists(String docId) throws IOException {
        return switchTarget(docId).exists(docId);
    }

    @Override
    public ESPageList<JSONObject> queryList(String indexName, String preQueryFilter, SearchParams params) {
        return switchTarget(indexName).queryList(clearSymbol(indexName), preQueryFilter,params);
    }

    @Override
    public ESPageList<JSONObject> querySuggest(String indexName, String preQueryFilter, SearchParams params) {
        return switchTarget(indexName).querySuggest(clearSymbol(indexName), preQueryFilter,params);
    }

    @Override
    public byte[] download(String id) {
        return switchTarget(id).download(id);
    }

    @Override
    public String queryExport(String indexName, SearchParams params) {
        return switchTarget(indexName).queryExport(clearSymbol(indexName),params);
    }

    @Override
    public ESPageList<JSONObject> queryList(String indexName, String preQueryFilter, SearchParams params, boolean filterByDocPerm) {
        return switchTarget(indexName).queryList(clearSymbol(indexName),preQueryFilter,params,filterByDocPerm);
    }

    @Override
    protected Class<NkDocSearchService> targetType() {
        return NkDocSearchService.class;
    }
}
